<template>
	<view class="container" v-if="isload" ref="productRef" :class="showmask ? '' : ''">
		<view class="carousel">
			<swiper indicator-dots circular=true duration="400" v-if="goodDetail&& goodDetail.galleryList && goodDetail.galleryList.length">
				<swiper-item class="swiper-item" v-for="(item,index) in goodDetail.galleryList" :key="index">
					<view class="image-wrapper">
						<image :src="item" class="loaded" mode="aspectFill"></image>
					</view>
				</swiper-item>
			</swiper>
			<block v-else-if="goodDetail">
				<image :src="goodDetail.goodsImg" class="image-wrapper" mode="aspectFill"></image>
			</block>
		</view>

		<view class="introduce-section">
			<text class="title">{{goodDetail.goodsName}}</text>
			<view v-if="!goodDetail.isAvoid" class="price-box">
				<text class="price">￥{{currentSku? currentSku.specPrice: goodDetail.shopPrice}}</text>
        <text class="price-tip"> </text>
        <text class="m-price" v-if="goodDetail.marketPrice != goodDetail.shopPrice ">￥{{currentSku? currentSku.marketPrice: goodDetail.marketPrice}} </text>
				<text class="coupon-tip" v-if="currentSku">会员价：{{currentSku.shopVipPrice}}</text>
        <view class="share-pos" @click="shareHandle">
          <image  src="/static/icon/share.png"></image>
        </view>
      </view>
			<view v-else class="price-box">
				<text class="price">{{goodDetail.shopVipPrice}}</text>
        <text class="price-tip"> 元</text>
        <text class="m-price" v-if="goodDetail.shopPrice != goodDetail.shopVipPrice ">￥{{goodDetail.shopPrice}} </text>
      </view>

			<view class="price-box">
				<text class="price" v-if="goodDetail.rebatePv >0">让利：{{goodDetail.rebatePv}}</text>
				<text class="price" style="margin-left: 15px;" v-if="goodDetail.rebate_gg_credit>0">消费奖励：{{goodDetail.rebate_gg_credit}}</text>
			</view>
			<view class="bot-row">
				<text v-if="goodDetail.isAvoid == 0">销量: {{ goodDetail.saleNum}}</text>
				<text v-if="goodDetail.isAvoid == 1">运费: {{ goodDetail.goodsFreight}}</text>
				<text>库存: {{currentSku? currentSku.specStock:goodDetail.goodsStock}}</text>
				<text>浏览量: {{goodDetail.visitNum}}</text>
			</view>
			<view class="score" v-if="goodDetail.discount">
				<text class='costScore'>{{goodDetail.discount.costScore}}</text>积分可兑换<text class="recharge">{{goodDetail.discount.reduceMoney}}</text>
			</view>
		</view>
		<specsList :specs="goodDetail.goodsSpecs.selector" @commitSelect="selectSpecs" v-if="goodDetail.goodsSpecs"></specsList>
		<view class="group-list" v-if="ptinfo && isAllStart == 0 && !ptinfo.isMy || participantslist.length!=0 &&  isgift !=1  && !ptinfo.isMy">
			<view class="participants" v-if="participantslist.length!=0">
				<view class="num">
					{{participantslist.length}}人在拼单，可直接参与
				</view>
				<!-- #ifdef APP-PLUS -->
				<view class="sharebtn">
					<button type="default" class="yqdoPin" @click="shareApp">邀请</button>
				</view>
				<!-- #endif -->
				<!-- #ifdef H5 || MP-WEIXIN -->
				<button @click="invite(goodDetail.goodsImg,ptinfo.pintuanStartId,ptinfo.pintuanId,goodDetail.goodsId)" type="default"
				 class="yqdoPin" open-type="share">邀请</button>
				<!-- #endif -->
				<view class="checkmore" @click="openGroupmaxk">
					查看更多>
				</view>
			</view>
			<view class="participants-user-list" v-for="(item,index) in participantslist" v-if="index <= 1" :key="index">
				<view class="user-Bgiamge">
					<image class="portrait" :src="item.userPhoto" mode="aspectFill"></image>
					<text class="name">{{item.userName}}</text>
				</view>
				<view class="participants-status">
					<view class="difference">还差<text>{{ptinfo.needUserCount - item.curUserCount}}</text>拼成</view>
					<!-- <view>剩余{{endText}}</view> -->
				</view>
				<view class="doPin" @click="joinbuying(item.pintuanStartId,item.goodsSpecId,goodDetail.goodsId)">去拼单</view>
			</view>
		</view>



		<view v-if="isformorder != ''">
			<view class="commentCell">
				<view class="pinTitle" v-if="piners.length != 0 && isformorder == 0">
					<view class="pinStatus">
						还差
						<text>{{ptinfo.needUserCount - piners.length}}人</text>
						拼成
					</view>
					<!-- #ifdef APP-PLUS -->
					<view class="sharebtn">
						<button type="default" class="yqdoPin" @click="shareApp">邀请进团</button>
					</view>
					<!-- #endif -->
					<!-- #ifdef H5 || MP-WEIXIN -->
					<button type="default" class="yqdoPin" open-type="share">邀请进团</button>
					<!-- #endif -->
				</view>
				<view class="ponerBox">
					<view class="pinerItem" v-for="(item,index) in piners" :key="index">
						<image :src="item.userPhoto" class="pinerHeadImg" mode=""></image>
						<view class="PinerName">
							<view>{{item.userName}}</view>
							<view v-show="item.pintuanState !=0" :class="item.pintuanState == 1?'ptsuccess':'ptfail'">{{item.pintuanState==1?'拼团成功':'拼团失败'}}</view>
							<view v-show="item.pintuanState ==0" class="ptsuccess">参与中</view>
						</view>

					</view>
				</view>
			</view>
		</view>
		<view v-else>
			<view class="commentCell" v-if="ptinfo && isAllStart == 1 ||  piners.length != 0 && isgift!=1 &&  ptinfo.isMy">
				<view class="pinTitle" v-if="piners.length != 0 && isformorder == 0">
					<view class="pinStatus">
						还差
						<text>{{ptinfo.needUserCount - piners.length}}人</text>
						拼成
					</view>
					<!-- #ifdef APP-PLUS -->

					<view class="sharebtn">
						<button type="default" class="yqdoPin" @click="shareApp">邀请进团</button>
					</view>

					<!-- #endif -->

					<!-- #ifdef H5 || MP-WEIXIN -->

					<button type="default" class="yqdoPin" open-type="share">邀请进团</button>

					<!-- #endif -->
				</view>
				<view class="ponerBox">
					<view class="pinerItem" v-for="(item,index) in piners" :key="index">
						<image :src="item.userPhoto" class="pinerHeadImg" mode=""></image>
						<view class="PinerName">
							<view>{{item.userName}}</view>
							<view v-show="item.pintuanState !=0" :class="item.pintuanState == 1?'ptsuccess':'ptfail'">{{item.pintuanState==1?'拼团成功':'拼团失败'}}</view>
							<view v-show="item.pintuanState ==0" class="ptsuccess">参与中</view>
						</view>

					</view>
				</view>
			</view>
		</view>







		<!-- 遮罩 -->
		<view class="pt-pop">
			<uni-popup @change="maskchange" ref="popup" type="center">
				<view class="pt-popup-wrap">
					<view class="title">正在拼单</view>
					<view class="participants">
						<view class="participants-user-list" v-for="(item,index) in participantslist" :key="index">
							<view class="user-Bgiamge">
								<image class="portrait" :src="item.userPhoto" mode=""></image>
								<view class="info">
									<view class="name">
										<view class="user">{{iteshopPricem.userName}}</view>
										<text>还差<text class="count">{{ptinfo.needUserCount - item.curUserCount}}人</text>拼成</text>
									</view>
									<!-- <view class="participants-status">剩余{{endText}}</view> -->
								</view>
							</view>
							<view class="doPin" @click="joinbuying(item.pintuanStartId,item.goodsSpecId)">去拼单</view>
						</view>
					</view>
				</view>
			</uni-popup>
		</view>
		<view class="commentCell" v-if="goodDetail">
			<list-cell icon="icon-pinglun-copy" iconColor="#ee883b" title="商品评价" :tips="goodDetail.appraisesNum+''" @eventClick="toProductComment"></list-cell>
		</view>
		<view class="shopBox" v-if="shop" @click="toshoplist(shop.shopId)">
			<image :src="shop.shopImg" class="shopImg" mode="aspectFill"></image>

			<view class="shopContext">
				<view class="shopName">
					{{shop.shopName}}
				</view>
				<view class="shopAddress">
					门店地址：{{shop.shopAddress}}
				</view>
				<view class="shopRange">
					经验范围：
					<block v-for="(item,index) in shop.majorCateNames" :key="index">
						<text>{{item}}</text>
					</block>
				</view>
			</view>
		</view>


		<view class="detail-desc">
			<view class="d-header">
				<text>图文详情</text>
			</view>
			<rich-text class="richtext" :nodes="desc"></rich-text>
		</view>

		<!-- 底部操作菜单 v-if="goodDetail.isAppointment != 1 && goodDetail.isFreeAppointment != 1" -->
		<view class="page-bottom" >
			<navigator url="/pages/index/index" open-type="switchTab" class="p-b-btn">
				<text class="yticon icon-xiatubiao--copy"></text>
				<text>首页</text>
			</navigator>
			<!-- <navigator url="/pages/cart/cart" open-type="switchTab" class="p-b-btn">
				<text class="yticon icon-gouwuche"></text>
				<text>购物车</text>
			</navigator> -->
			<!-- <view class="p-b-btn" :class="{active: favorite}" @click="toFavorite">
				<text class="yticon icon-shoucang"></text>
				<text>收藏</text>
			</view> -->
			<block v-if="goodDetail.isExchange">
				<view class="action-btn-group singer-btn" style="width:100%">
					<button type="primary" class=" action-btn no-border buy-now-btn" @click="toexchangeDetail(goodDetail.goodsId)">立即兑换</button>
				</view>
			</block>
			<block v-else-if="goodDetail.isAvoid">
				<view class="action-btn-group singer-btn" style="width:100%">
					<button type="primary" class=" action-btn no-border buy-now-btn" @click="buy()">立即领取</button>
				</view>
			</block>
			<block v-else>
				<view class="action-btn-group" v-if="ptinfo">
					<button type="primary" class=" action-btn no-border buy-now-btn" @click="buy">立即购买</button>
					<button type="primary" class=" action-btn no-border add-cart-btn" @click="toggleSpec">加入购物车</button>
					<button type="primary" v-if="ptinfo.pintuanStartId != 0 && isgift !=1" class=" action-btn no-border add-cart-btn"
					 @click="joinbuying(ptinfo.pintuanStartId,ptinfo.goodsSpecId,goodDetail.goodsId,ptinfo.isMy)">参与拼团</button>
					<button type="primary" v-if="ptinfo.pintuanStartId == 0 && ptinfo" class=" action-btn no-border add-cart-btn"
					 @click="joinPin(ptinfo)">发起拼团</button>
				</view>
				<view class="action-btn-group" v-else-if="is_sq == 1"  style="width: 100%;">
					<button type="primary" class=" action-btn no-border buy-now-btn" @click="backtoAppointment(shop.shopId)">立即购买</button>
				</view>
				<view class="action-btn-group" v-else>
					<button type="primary" class=" action-btn no-border buy-now-btn" @click="buy">立即购买</button>
					<button type="primary" class=" action-btn no-border add-cart-btn"  @click="toggleSpec">加入购物车</button>
				</view>
			</block>

		</view>


		<!-- 规格-模态层弹窗 -->
		<view class="popup spec" :class="specClass" @touchmove.stop.prevent="stopPrevent" @click="toggleSpec">
			<!-- 遮罩层 -->
			<view class="mask"></view>
			<view class="layer attr-content" @click.stop="stopPrevent">
				<view class="a-t">
					<image :src="goodDetail.goodsImg"></image>
					<view class="right">
						<text class="price" v-if="goodDetail.isAvoid">¥{{goodDetail.shopVipPrice}}</text>
						<text class="price" v-else>¥{{currentSku? currentSku.specPrice: goodDetail.shopPrice}}</text>
						<text class="stock">库存：{{currentSku?currentSku.specStock:goodDetail.goodsStock}}</text>
						<text></text>
						<!-- <view class="selected" v-if="currentSku">
							已选：
							<text class="selected-text" v-for="(sItem, sIndex) in specSelected" :key="sIndex">
								{{sItem.name}}
							</text>
						</view> -->
					</view>
				</view>
				<!-- <view v-for="(item,index) in specList" :key="index" v-if="goodDetail.goodsSpecs" class="attr-list">
					<text>{{item.name}}</text>
					<view class="item-list">
						<text v-for="(childItem, childIndex) in specChildList" v-if="childItem.pid === item.id" :key="childIndex" class="tit"
						 :class="{selected: childItem.selected}" @click="selectSpec(childIndex, childItem.pid)">
							{{childItem.name}}
						</text>
					</view>
				</view> -->
				<block v-if="goodDetail.goodsSpecs&& goodDetail.goodsSpecs.selector &&　goodDetail.goodsSpecs.selector.length">
					<specsList :specs="goodDetail.goodsSpecs.selector" @commitSelect="selectSpecs"></specsList>
				</block>

				<view class="numRow">
					<view class="myStep">
						<text class="yticon icon--jianhao" @click="numChange('ninus')"></text>
						<input type="number" @input="numInput" :value="catNum" />
						<text class="yticon icon-jia1" @click="numChange('plus')"></text>
					</view>
				</view>
				<button class="btn" @click="toggleSpec('addCat')">完成</button>
			</view>
		</view>
		<!-- 分享 -->
		 <share-poster
         ref="share"
         :qrcodeVal="qrcodeVal"
         :slogan="['这里的正品品牌只要“半价”？好运凑一凑就有啦～']"
     />
	</view>
</template>
<!-- <script src="https://cdn.jsdelivr.net/npm/eruda"></script>
<script>
	eruda.init();
</script> -->
<script>
  import siteInfo from "@/siteInfo.js"
	import uniPopup from '@/components/uni-popup/uni-popup.vue'
	import uniIcon from '@/components/uni-icons/uni-icons.vue'
	import listCell from '@/components/mix-list-cell'
	import specsList from "@/components/specsList/specsList.vue"
  import sharePoster from "@/components/share-poster.vue"
  export default {
		components: {
			uniPopup,
			specsList,
			uniIcon,
			listCell,
      sharePoster
		},
		data() {
			return {
				is_sq:0,
				desc: '',
				isgift: '',
				pintuanStartId: '',
				sharegoodsId: '',
				loginUserId: '',
				inviteUserId: '',
				shareimg: '',
				ptid: '',
				ptidstart: '',
				skuid: '',
				ptinfo: {},
				isAllStart: '',
				participantslist: [],
				scrollTop: 0,
				showmask: false,
				goodsId: 0,
				endPin: '2020/07/25,15:00',
				endText: '',
				countInterval: null,
				currentSku: null,
				goodDetail: null,
				buyIt: false,
				shop: null,
				specClass: 'none',
				specSelected: [],
				catNum: 1,
				favorite: true,
				type: 0,
				piners: [],
				isformorder: '',
				isload: false,
			};
		},
		onShow() {
			this.countDown()
		},
		async onLoad(options) {
			let that = this;
			//接收传值,id里面放的是标题，因为测试数据并没写id 
			this.goodsId = options.id;
			this.isgift = options.isgift
			this.isAllStart = options.isAllStart
			console.log(options)
			if (options.pintuanStartId) {
				this.pintuanStartId = options.pintuanStartId;
				this.isformorder = options.isformorder
			}
			if (options.inviteUserId) {
				console.log('通过分享后的链接进来')
				this.inviteUserId = options.inviteUserId;
				this.onrecommend()
			}
			if(options.is_sq){
				this.is_sq = options.is_sq
			}
			this.loadDetail();
			//规格 默认选中第一条
			// this.specList.forEach(item => {
			// 	for (let cItem of this.specChildList) {
			// 		if (cItem.pid === item.id) {
			// 			this.$set(cItem, 'selected', true);
			// 			this.specSelected.push(cItem);
			// 			break; //forEach不能使用break
			// 		}
			// 	}
			// })
			// this.shareList = await this.$api.json('shareList');
		},
		onPageScroll(scrollTop) {
			this.scrollTop = scrollTop
		},
		onUnload() {
			clearInterval(this.countInterval)
		},
    onBackPress(e){
      uni.setStorageSync('goodsBack', 1)
    },
		onHide() {
			clearInterval(this.countInterval)
		},
		methods: {
			toshoplist(id) {
				uni.navigateTo({
					url: '/district/districtDetail/districtDetail?shopId=' + id
				})
			},
			toexchangeDetail(id){
				var shop_ = JSON.stringify(this.shop)
				uni.navigateTo({
					url: '/district/exchange/exchangeorder?goodsId=' + id + "&shop=" + shop_
				})
			},
			shareApp() {
				console.log('1')
				// uni.share({
				//     provider: 'weixin',
				//     scene: "WXSceneSession",
				//     type: 5,
				//     imageUrl: 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/app/share-logo@3.png',
				//     title: '欢迎体验uniapp',
				//     miniProgram: {
				//         id: 'gh_abcdefg',
				//         path: 'pages/index/index',
				//         type: 0,
				//         webUrl: 'http://uniapp.dcloud.io'
				//     },
				//     success: ret => {
				//         console.log(JSON.stringify(ret));
				//     }
				// });
				uni.share({
					provider: 'weixin',
					scene: "WXSceneSession",
					type: 5,
					title: '好友邀请你来拼团啦~',
					miniProgram: {
						id:'gh_387796e0ad7e',
						path: 'pages/product/product?id=' + this.sharegoodsId + '&pintuanStartId=' + this.pintuanStartId + '&goodsId=' +
							this.goodsId + '&inviteUserId=' + this.loginUserId,
						type: 0,
						webUrl: 'http://gua.qinmaoyi.cn/mregister?inviteCode'
					},
					success: ret => {
						console.log(JSON.stringify(ret),'1');
					},
					fail: err => {
						console.log(JSON.stringify(err),'2')
					}
				});
			},
			onShareAppMessage(res) {
				let that = this;
				if(res.from == 'menu'){
					return {
						title: '有人邀请你来啦',
						path: '/pages/product/product?id=' + this.sharegoodsId + '&pintuanStartId=' + this.pintuanStartId + '&goodsId=' +
							this.goodsId + '&inviteUserId=' + that.loginUserId
					};
				}else{
					return {
						title: '有人邀请你来拼团啦',
						path: '/pages/product/product?id=' + this.sharegoodsId + '&pintuanStartId=' + this.pintuanStartId + '&goodsId=' +
							this.goodsId + '&inviteUserId=' + that.loginUserId
					};
				}
			
			},
			onrecommend() {
				//jilu\
				console.log('被邀请进来')
				let that = this;
				let data = {
					inviteUserId: that.inviteUserId,
					pintuanStartId: that.pintuanStartId,
					goodsId: that.goodsId
				}
				that.$Request.request('/api/pintuan/invitePintuan', 'POST', data).then(res => {

					console.log('被邀请人ID：' + that.inviteUserId)
				})
			},
			joinbuying(pintuanStartId, goodsSpecId, id, isMy) {
				let that = this;
				if (isMy) {
					that.$api.msg('已加入该拼团！')
					return;
				}
				that.$Request.request('/api/cart/add', 'POST', {
					type: 1,
					goodsId: id,
					buyNum: 1,
					goodsSpecId: goodsSpecId
				}).then(res => {
					if (res.status == 1) {
						uni.navigateTo({
							url: '../order/createOrder?pintuanGoodsId=' + id + '&pintuanStartId=' + pintuanStartId
						})
					}else{
					  throw res.msg
          }

				}).catch(err => {
					uni.showToast({
            title: err?.msg || err,
            icon: 'none'
          })
				})
				// uni.navigateTo({
				// 	url:`../order/createOrder`
				// })
			},
			maskchange(e) {
				let that = this;
				e.show == false ? that.showmask = false : that.showmask = true;
			},
			openGroupmaxk() {
				let that = this;
				// document.scrollTop = that.scrollTop
				that.$refs.popup.open()
				that.showmask = true;
			},
			countDown() {
				this.countInterval = setInterval(() => {
					let end = new Date(this.endPin)
					let now = new Date()
					if (end.getTime() > now.getTime()) {
						let minSec = parseInt((end.getTime() - now.getTime()) / 1000)
						let d = parseInt(minSec / (24 * 60 * 60))
						let h = parseInt(minSec / (60 * 60) % 24);
						let m = parseInt(minSec / 60 % 60);
						let s = parseInt(minSec % 60);
						if (d > 0) {
							this.endText = `${d}天${h}时${m}分${s}秒`
						} else {
							this.endText = `${h}时${m}分${s}秒`
						}

					}
				}, 1000)

			},
			joinPin(info) {
				let that = this;
				let data = {};
				if (info == null) {
					that.$api.msg('该商品不是拼团商品')
				}
				if (info.isMy) {
					that.$api.msg('已加入该拼团！')
					return;
				}
				if (that.goodDetail.goodsSpecs == null || that.goodDetail.goodsSpecs.selector.length == 0) {
					data = {
						goodsId: that.goodDetail.goodsId,
						buyNum: that.catNum
					}
				} else {
					if (that.currentSku) {
						data = {
							goodsSpecId: that.currentSku.goodsSpecId,
							buyNum: that.catNum
						}
					} else if (!that.currentSku && that.goodDetail.goodsSpecs && that.goodDetail.goodsSpecs.selector.length != 0) {
						that.$api.msg('请选择规格！')
						return
					}
				}
				// if (this.buyIt) {
				data.type = 1
				// } else {
				// data.type = 0
				// }
				that.$Request.request('/api/cart/add', 'POST', data).then(res => {
					if (res.status == 1) {
						uni.navigateTo({
							url: '../order/createOrder?pintuanGoodsId=' + that.goodDetail.goodsId + '&pintuanStartId=' + info.pintuanStartId
						})
					}

				}).catch(err => {
          uni.showToast({
            title: err?.msg || err,
            icon: 'none'
          })
					console.log(err)
				})
				// this.$api.msg("参与拼团！");
			},
			toProductComment() {
				uni.navigateTo({
					url: '/subPackage/productComments/productComments?goodsId=' + this.goodDetail.goodsId
				})
			},
			cartNumChange(e) {
				// this.catNum = e.number
			},
			numInput(e) {
				let max = this.currentSku ? this.currentSku.specStock : this.goodDetail.goodsStock
				max = parseInt(max)
				let num = parseInt(e.detail.value)
				if (num > max) {
					this.catNum = max
				} else if (num <= 0) {
					this.catNum = 1
				} else {

					this.catNum = num
				}
			},
			numChange(type) {
				// if(this.isfree == 1){
				// 	this.$api.msg('该商品为免单只可购买1个')
				// 	return;
				// }
				let max = this.currentSku ? this.currentSku.specStock : this.goodDetail.goodsStock
				max = parseInt(max)
				let num = this.catNum

				if (type == 'plus') {
					num++
				} else {
					num--
				}
				if (num > max) {
					this.catNum = max
				} else if (num <= 0) {
					this.catNum = 1
				} else {

					this.catNum = num
				}
			},
			sku() {
				let arr = []
				this.currentSku = null
				this.goodDetail.goodsSpecs.selector.forEach(item => {
					item.items.forEach(spec => {
						if (spec.select) {
							arr.push(spec.itemId)
						}
					})
				})
				if (arr.length == this.goodDetail.goodsSpecs.selector.length) {
					arr.sort()
					let key = arr.join(':')
					this.currentSku = this.goodDetail.goodsSpecs.sku[key]

				}
			},
			selectSpecs(selectObj) {
				this.skuid = selectObj.id;
				let fa = this.goodDetail.goodsSpecs.selector[selectObj.level]
				for (let i in fa.items) {
					let item = fa.items[i]
					if (item.itemId == selectObj.id) {
						item.select = true
					} else {
						item.select = false
					}
				}
				this.goodDetail.goodsSpecs.selector.splice(selectObj.level, fa)
				this.sku()
			},
			loadDetail() {
				// that.goodsId
				let that = this
				that.$Request.request('/api/goods/detail', 'GET', {
					goodsId: that.goodsId,
					pintuanStartId: this.pintuanStartId || '',
				}).then(res => {
					console.log(res)
					if (res.data) {
						that.goodDetail = res.data.goods
						that.desc = res.data.goods.goodsDesc.replace(/\<img\s/gi,
							'<img style="max-width:100%;height:auto;display: block;" ')
						that.isload = true;
						that.shop = res.data.shop
						that.loginUserId = res.data.loginUserId
						that.ptinfo = res.data.pintuan ? res.data.pintuan : {};
						that.isAllStart = that.ptinfo.isAllStart
						that.piners = res.data.pintuan ? res.data.pintuan.userList : []
						that.participantslist = res.data.pintuan ? res.data.pintuan.pintuanStartList : []
						that.sharegoodsId = that.goodDetail.goodsId;
						that.pintuanStartId = that.ptinfo.pintuanStartId;
					} else {
						that.$api.msg('获取商品数据出现异常')
						uni.navigateBack()
					}
				}).catch(err => {
					console.log(err)
				})
			},
			//规格弹窗开关
			toggleSpec(type) {
				if (this.specClass === 'show') {
					if (type == 'addCat') {
						let that = this
						let data = {}
						if (that.goodDetail.goodsSpecs == null || that.goodDetail.goodsSpecs.selector.length == 0) {
							data = {
								goodsId: that.goodDetail.goodsId,
								buyNum: that.catNum
							}
						} else {
							if (that.currentSku) {
								data = {
									goodsSpecId: that.currentSku.goodsSpecId,
									buyNum: that.catNum
								}
							} else if (!that.currentSku && that.goodDetail.goodsSpecs && that.goodDetail.goodsSpecs.selector.length != 0) {
								that.$api.msg('请选择规格！')
								return
							}
						}

						if (this.buyIt) {
							data.type = 1
						} else {
							data.type = 0
						}
						that.$Request.request('/api/cart/add', 'POST', data).then(res => {
							console.log(res)
							// return;
							if (res.status == 1) {
								if (res.msg && res.msg.cartId) {
									if (!that.buyIt) {
										that.$api.msg('加入购物车成功！')
									}
									setTimeout(() => {
										if (that.buyIt) {
											uni.navigateTo({
												url: '/pages/order/createOrder?cartId=' + res.msg.cartId
											})
										} else {
											uni.switchTab({
												url: '/pages/cart/cart'
											})
										}
										that.specClass = 'hide';
										setTimeout(() => {
											that.specClass = 'none';
										}, 250);
									}, 800)
								} else {
									that.$api.msg('加入购物车失败！')
									that.buyIt = false
									setTimeout(() => {
										that.specClass = 'hide';
										setTimeout(() => {
											that.specClass = 'none';
										}, 250);
									}, 800)
								}
							}else{
							  throw res.msg
              }

						}).catch(err => {
              uni.showToast({
                title: err?.msg || err,
                icon: 'none'
              })
							console.log(err)
							that.buyIt = false
						})
					} else {
						this.specClass = 'hide';
						this.buyIt = false
						setTimeout(() => {
							this.specClass = 'none';
						}, 250);
					}

				} else if (this.specClass === 'none') {
					this.specClass = 'show';
					this.buyIt = false
				}
			},
			backtoAppointment(id){
				uni.navigateTo({
					url:'/district/appointment/appointment?shopId='+id
				})
			},
			//分享
			share() {
				this.$refs.share.toggleMask();
			},
      shareHandle(){
        this.$refs.share.open();
      },
			//收藏
			toFavorite() {
				this.favorite = !this.favorite;
			},
			buy() {
				this.toggleSpec()
				this.buyIt = true
				// uni.navigateTo({
				// 	url: `/pages/order/createOrder`
				// })
			},
			stopPrevent() {}
		},
    computed:{
      qrcodeVal(){
        return `${siteInfo.root}/static/app/index.html?v1&share=ymyx@gs@id`+this.goodsId
      }
    }
	}
</script>
<style>

</style>
<style lang='scss'>
	.richtext {}

	.pervent {
		width: 100%;
		height: 100%;
		position: fixed;
		overflow: hidden;
	}

	.pinTitle uni-button,
	button {}

	.yqdoPin {
		color: #fff !important;
		background-color: #e02f25 !important;
		border-radius: 4px;
		margin: 0;
		width: 85px;
		font-size: 12px;
		height: 25px;
		line-height: 25px;
		margin: 0;
	}

	.ptsuccess {
		color: rgb(255, 255, 255);
		background-color: #027aff;
		border-radius: 10upx;
		width: 120upx;
		height: 40upx;
		line-height: 40upx;
		text-align: center;
		font-size: 18upx;
		margin-top: 10upx;
	}

	.ptfail {
		color: rgb(255, 255, 255);
		background-color: #e02f25;
		border-radius: 10upx;
		width: 120upx;
		height: 40upx;
		line-height: 40upx;
		text-align: center;
		font-size: 20upx;
		margin-top: 10upx;
	}

  .share-pos{
    float: right;
    image{
      width: 40upx; height: 40upx;
    }
  }
  .price-box{
    display: block!important;
  }
	@import './product.scss'
</style>
